//
//  Status.swift
//  weibo
//
//  Created by yellow on 15/10/19.
//  Copyright © 2015年 yellow. All rights reserved.
//

import UIKit


//微博模型
class Status: NSObject {
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博创建时间
    var created_at: String?
    /// 微博来源
    var source: String?
    /// 微博用户对象
    var user:User?
    /// 转发微博
    var retweeted_status:Status?
    
    /// 微博配图数组，thumbnail_pic为单项的key，没有配图返回空
    var pic_urls:[[String:String]]?

    
    init(dict:[String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    //重写该方法是因为user是一个复合属性，默认情况下会把user设置为一个字典
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            //当数据为[String:AnyObject]格式是进行kvc
            if let dict = value as? [String:AnyObject]{
                user = User(dict: dict)
            }
            return
        }
        
        if key == "retweeted_status" {
            //当数据为[String:AnyObject]格式是进行kvc
            if let dict = value as? [String:AnyObject]{
                retweeted_status = Status(dict: dict)
            }
            return
        }
        
        
        //其他key的设置
        super.setValue(value, forKey: key)
    }
    

    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    //重写对象的描述
    override  var description:String{
        let keys = ["id","text","created_at","source","user","retweeted_status"]
        return  dictionaryWithValuesForKeys(keys).description
    }
}
